<?php session_start();
include('functions.php');
$dir = $_GET['dir'];
if (isset($dir)) {
if(isset($_GET['file'])) {
$file = $_GET['file'];
}
if ($_SESSION["pass"] != check($_SESSION["user"])) {
  secure();
}
?>
<html>
<head>
<title>oPanel V<?php echo $ver; ?></title>
<link REL="shortcut icon" HREF="images/favicon.ico" TYPE="image/x-icon">
<link rel="stylesheet"href="style.css">
</head>
<body>
<?php
if($_GET['del'] != true) {
if(isset($file)) {
echo '<center><img src="images/logo.png"></center>';
die('<script type="text/javascript">
var answer = confirm("Are you sure you want to delete that file?")
         if (answer){
     window.location = "http://'. $_SERVER["HTTP_HOST"].''.dirname("$_SERVER[SCRIPT_NAME]").'/trashit.php?dir='.$dir.'&file='.$file.'&del=true";
         }else{
         alert("delete has been cancelled");
     window.location = "http://'.$_SERVER["HTTP_HOST"].''.dirname("$_SERVER[SCRIPT_NAME]").'/dirstuff.php";
         }
</script>');
} else {
echo '<center><img src="images/logo.png"></center>';
die('<script type="text/javascript">
var answer = confirm("Are you sure you want to delete that file?")
         if (answer){
     window.location = "http://'. $_SERVER["HTTP_HOST"].''.dirname("$_SERVER[SCRIPT_NAME]").'/trashit.php?dir='.$dir.'&del=true";
         }else{
         alert("delete has been cancelled");
     window.location = "http://'.$_SERVER["HTTP_HOST"].''.dirname("$_SERVER[SCRIPT_NAME]").'/dirstuff.php";
         }
</script>');
}
}
if(isset($_GET['file'])) {
$file = $_GET['file'];
$var1 = explode(".", $file);
if($var1[0] != "") {
$var2 = str_replace(" ", "_", $var1[0]);
} else {
$var2 = str_replace(" ", "_", $var1[1]);
}
$var = addslashes($var2);
$somecontent = "<?php $$var = '$dir'; ?>\n\n";
} else {
$var = basename($dir);
$path = dirname($dir)."/";
$somecontent = "<?php $$var = '$path'; ?>\n\n";
}
if (is_writable($_SESSION["trashfile"])) {
   if (!$handle = fopen($_SESSION["trashfile"], 'a+')) {
         die("Cannot open file ($filename)");
         exit;
   }
   if (fwrite($handle, $somecontent) === FALSE) {
       die("Cannot write to a needed file ($filename)");
       exit;
   }
  
  
   fclose($handle);

} else {
   die("a needed file is not writable ($_SESSION[trashfile])");
}
if(isset($_GET['file'])) {
rename("$dir$file", "$_SESSION[trashdir]$file");
} else {
rename("$dir$file", "$_SESSION[trashdir]$var");
}
echo '<center><img src="images/logo.png"></center>';
echo "<br>File has been deleted.";
}
?>
<script>
<!--
function wait(delay){
string="pauseforalert();";
setTimeout(string,delay);
}
function pauseforalert(){
<?php if(isset($file)) { ?>
parent.filemain.location="http://<?php echo $_SERVER["HTTP_HOST"]; echo dirname("$_SERVER[SCRIPT_NAME]"); ?>/list.php?dir=<?php echo $dir; ?>";
<?php } else { ?>
parent.filemain.location="http://<?php echo $_SERVER["HTTP_HOST"]; echo dirname("$_SERVER[SCRIPT_NAME]"); ?>/list.php?dir=<?php echo $path; ?>";
<?php } ?>
parent.trashframe.location="http://<?php echo $_SERVER["HTTP_HOST"]; echo dirname("$_SERVER[SCRIPT_NAME]"); ?>/trash.php";
}
// -->
</script>
<script type="text/javascript">
wait(1000)
</script>

</body>
</html>

